package com.troll.wanandroid.adapter.home

import android.text.Html
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.troll.eth.ex.load
import com.troll.eth.ex.removeAllBank
import com.troll.wanandroid.R
import com.troll.wanandroid.model.ArticleIntroduction

/**
 *
 * @Author:   TangPeng
 * @Time:     2/2/21
 * @Remark:
 */
class HomeAdapter :
    BaseQuickAdapter<ArticleIntroduction, BaseViewHolder>(R.layout.layout_adapter_article) {

    override fun convert(holder: BaseViewHolder, item: ArticleIntroduction) {
        item.let {
            holder.setText(R.id.tv_author, it.author)
                .setVisible(R.id.tv_new, it.fresh)
                .setText(R.id.tv_title, Html.fromHtml(item.title))
                .setText(R.id.tv_time, item.niceData)
                .setText(R.id.tv_desc, Html.fromHtml(item.desc).toString().removeAllBank(2))

            holder.getView<ImageView>(R.id.iv_img)
                .load(source = "https://ae01.alicdn.com/kf/Uec00959acd9c4d0aa900d5fb8ea481931.jpg")

            item.tags?.let { tags ->
                if (tags.size > 0) {
                    holder.setText(R.id.tv_tag, tags[0].name)
                } else {
                    holder.setVisible(R.id.tv_tag, false)
                }
            }
        }
    }

}